#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
const int MAXN=1e6+10;
LL n,p[MAXN],c[MAXN],A[MAXN],B[MAXN],q[MAXN],f[MAXN];
db slope(LL x,LL y)
{
	return (f[x]-f[y]+B[x]-B[y])*1.0/(A[x]-A[y]);
}
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;++i)
		scanf("%lld",&c[i]);
	for(LL i=1;i<=n;++i)
		scanf("%lld",&p[i]);
	for(LL i=1;i<=n;++i)
	{
		A[i]=A[i-1]+p[i];
		B[i]=B[i-1]+i*p[i];
	}
	LL l=0,r=0;
	for(LL i=1;i<=n;++i)
	{
		while(l<r&&slope(q[l],q[l+1])<i)++l;
		LL t=q[l];
		f[i]=f[t]+i*(A[i]-A[t])-(B[i]-B[t])+c[i];
		while(l<r&&slope(q[r-1],q[r])>=slope(q[r],i))--r;
		q[++r]=i;
	}
	printf("%lld\n",f[n]);
	return 0;
}
